import request from '@/utils/request'
import { otherFiltersItem } from '@/utils'

/**
 * 根据区间编码获取数据
 * @param {string} displayAreaCode
 * @param {string} conventionNum 常规款数量
 * @returns
 */
export function queryDetailByAreaCode(displayAreaCode, conventionNum, shopCode) {
  return request({
    url: `/api/v1/displayRecommendedSample/detail/${displayAreaCode}/${conventionNum}/${shopCode}`,
    method: 'post'
  })
}

/**
 * 替换
 * @param {object} data
 * @returns
 */
export function saveChange(data) {
  return request({
    url: `/api/v1/displaySampleRankingRelation`,
    method: 'put',
    data
  })
}

/**
 * 保存上样清单
 * @param {Array} data
 * @returns
 */
export function saveRecommend(data) {
  return request({
    url: `/api/v1/displaySampleRankingRelation`,
    method: 'post',
    data
  })
}
/**
 * 获取主表数据
 * @param {object} otherFilter
 * @returns
 */
export function queryMainData(otherFilter) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify(otherFilter))
  return request({
    url: `/api/v1/displayRecommendedSample/page`,
    method: 'post',
    data
  })
}

/**
 * 根据spuId和skuId获取商品详情页
 * @param {string} spuId
 * @param {string} skuId
 * @returns
 */
export function queryDetailData(spuId, skuId, customerCode) {
  return request({
    url: `/api/v1/productDetail/info`,
    method: 'get',
    params: { 'spuId': spuId, 'skuId': skuId, 'customerCode': customerCode }
  })
}

/**
 * 查询产品搭配--促销款形象款
 * @param {string} mdmCode
 * @returns
 */
export function queryMatchData(mdmCode, customerCode) {
  return request({
    url: `/api/v1/furnishingShow/match/${mdmCode}/?customerCode=${customerCode}`,
    method: 'post'
  })
}

/**
 * 查询产品搭配--常规款
 * @param {string} mdmCode
 * @returns
 */
export function queryNormalMatch(code) {
  const data = new FormData()
  data.append('pageFlag', false)
  data.append('filtersRaw', JSON.stringify([otherFiltersItem('productCode', code, '=')]))
  return request({
    url: `/api/v1/displayProductCollocation/page`,
    method: 'post',
    data
  })
}
